package rahmath.sharif.docrypt.util;

import java.io.File;
import java.net.URLConnection;

import rahmath.sharif.docrypt.R;

public class MimeUtil {
	private static final String IMAGE = "image";
	private static final String AUDIO = "audio";
	private static final String MUSIC = "music";
	private static final String VIDEO = "video";
	private static final String OFFICE = "officedocument";
	private static final String OPENDOC = "opendocument";
	private static final String TEXT = "text";
	private static final String PDF = "pdf";
	private static final String APK = "application/vnd.android.package-archive";
	private static final String ZIP = "zip";
	private static final String COMPRESSED = "compressed";

	public static int getDrawableForFile(File file) {
		String mimeString = null;
		try {
			mimeString = URLConnection.guessContentTypeFromName(file
					.getAbsolutePath());
		} catch (Exception e) {
		}
		if (null != mimeString) {
			if (mimeString.contains(IMAGE)) {
				return R.drawable.ic_action_image;
			} else if (mimeString.contains(AUDIO) || mimeString.contains(MUSIC)) {
				return R.drawable.ic_action_audio;
			} else if (mimeString.contains(PDF)) {
				return R.drawable.ic_action_pdf;
			} else if (mimeString.contains(OFFICE)
					|| mimeString.contains(OPENDOC)
					|| mimeString.contains(TEXT)) {
				return R.drawable.ic_action_document;
			} else if (mimeString.contains(VIDEO)) {
				return R.drawable.ic_action_video;
			} else if (mimeString.contains(APK)) {
				return R.drawable.ic_action_apk;
			} else if (mimeString.contains(ZIP)
					|| mimeString.contains(COMPRESSED)) {
				return R.drawable.ic_action_zip;
			}
		}
		return R.drawable.ic_action_unknown_file;
	}
}
